package com.yimi.yinhepda.entity.response;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author 000432
 * @date 2017/4/8 0008
 * 建包的返回参数封装
 */

public class BuildPackageDetailResponse {

  private List<StockInfo> data;
  private boolean success;
  private String[] errorMessages;
  private int errorCode;

  public boolean isSuccess() {
    return success;
  }

  public void setSuccess(boolean success) {
    this.success = success;
  }

  public List<StockInfo> getData() {
    return data;
  }

  public void setData(List<StockInfo> data) {
    this.data = data;
  }

  public String[] getErrorMessages() {
    return errorMessages;
  }

  public void setErrorMessages(String[] errorMessages) {
    this.errorMessages = errorMessages;
  }

  public int getErrorCode() {
    return errorCode;
  }

  public void setErrorCode(int errorCode) {
    this.errorCode = errorCode;
  }

  /**
   * 建包的库存信息
   */
  public static class StockInfo implements Comparable<StockInfo>, Serializable {

    private static final long serialVersionUID = 101L;
    /** 运单号 */
    private String waybillNo;
    /** 开单件数 */
    private Integer srcPiecesNum;
    /** 库存件数 */
    private Integer piecesNum;
    /** 开单重量 */
    private BigDecimal weight;
    /** 开单体积 */
    private BigDecimal volume;
    /** 计费重量 */
    private BigDecimal chargedWeight;
    /** 运单路由 */
    private String waybillRoute;
    /** 包号 */
    private String packageNo;
    /** 到达库区 */
    private String billType;
    /** 单据类型：1 运单，2 包 */
    private String areaCode;
    /** 强扫标记 2为强扫，其他不是 */
    private String remark;
    /** 运单子单集合 */
    private List<ChildInfo> childList;

    public List<ChildInfo> getChildList() {
      return childList;
    }

    public void setChildList(List<ChildInfo> childList) {
      this.childList = childList;
    }

    public String getPackageNo() {
      return packageNo;
    }

    public void setPackageNo(String packageNo) {
      this.packageNo = packageNo;
    }

    public String getWaybillNo() {
      return waybillNo;
    }

    public void setWaybillNo(String waybillNo) {
      this.waybillNo = waybillNo;
    }

    public String getRemark() {
      return remark;
    }

    public void setRemark(String remark) {
      this.remark = remark;
    }

    public Integer getSrcPiecesNum() {
      if (srcPiecesNum == null) {
        return 0;
      }
      return srcPiecesNum;
    }

    public void setSrcPiecesNum(Integer srcPiecesNum) {
      this.srcPiecesNum = srcPiecesNum;
    }

    public BigDecimal getWeight() {
      if (weight == null) {
        weight = BigDecimal.ZERO;
      }
      return weight;
    }

    public void setWeight(BigDecimal weight) {
      this.weight = weight;
    }

    public BigDecimal getChargedWeight() {
      if (chargedWeight == null) {
        chargedWeight = BigDecimal.ZERO;
      }
      return chargedWeight;
    }

    public void setChargedWeight(BigDecimal chargedWeight) {
      this.chargedWeight = chargedWeight;
    }

    public String getAreaCode() {
      return areaCode;
    }

    public void setAreaCode(String areaCode) {
      this.areaCode = areaCode;
    }

    public String getBillType() {
      return billType;
    }

    public void setBillType(String billType) {
      this.billType = billType;
    }

    public BigDecimal getVolume() {
      if (volume == null) {
        volume = BigDecimal.ZERO;
      }
      return volume;
    }

    public void setVolume(BigDecimal volume) {
      this.volume = volume;
    }

    public Integer getPiecesNum() {
      if (piecesNum == null) {
        return 0;
      }
      return piecesNum;
    }

    public void setPiecesNum(Integer piecesNum) {
      this.piecesNum = piecesNum;
    }

    public String getWaybillRoute() {
      return waybillRoute;
    }

    public void setWaybillRoute(String waybillRoute) {
      this.waybillRoute = waybillRoute;
    }

    /**
     * 获取已经扫描的子单数量
     */

    public int getScannedNum() {
      int count = 0;
      for (ChildInfo childInfo : childList) {
        if (childInfo.getFlag() != null && childInfo.getFlag() == 1) {
          count++;
        }
      }
      return count;
    }

    /**
     * 对颜色的判断
     */
    public int justColorShow() {
      //开单
      int srcPiecesNum = getSrcPiecesNum();
      int scannedNum = getScannedNum();
      if (scannedNum == 0) {
        //白色
        return 1;
      } else if (scannedNum < srcPiecesNum) {
        //红色
        return 0;
      }
      if (scannedNum > srcPiecesNum) {
        //黄色
        return 2;
      } else {
        //绿色
        return 3;
      }
    }

    @Override public int compareTo(StockInfo stockInfo) {
      return this.justColorShow() - stockInfo.justColorShow();
    }

    //@Override public int describeContents() {
    //    return 0;
    //}
    //
    //@Override public void writeToParcel(Parcel dest, int flags) {
    //    dest.writeString(this.waybillNo);
    //    dest.writeValue(this.srcPiecesNum);
    //    dest.writeValue(this.piecesNum);
    //    dest.writeSerializable(this.weight);
    //    dest.writeSerializable(this.volume);
    //    dest.writeSerializable(this.chargedWeight);
    //    dest.writeString(this.waybillRoute);
    //    dest.writeString(this.packageNo);
    //    dest.writeString(this.billType);
    //    dest.writeString(this.areaCode);
    //    dest.writeString(this.remark);
    //    dest.writeList(this.childList);
    //}
    //
    //public StockInfo() {
    //}
    //
    //protected StockInfo(Parcel in) {
    //    this.waybillNo = in.readString();
    //    this.srcPiecesNum = (Integer) in.readValue(Integer.class.getClassLoader());
    //    this.piecesNum = (Integer) in.readValue(Integer.class.getClassLoader());
    //    this.weight = (BigDecimal) in.readSerializable();
    //    this.volume = (BigDecimal) in.readSerializable();
    //    this.chargedWeight = (BigDecimal) in.readSerializable();
    //    this.waybillRoute = in.readString();
    //    this.packageNo = in.readString();
    //    this.billType = in.readString();
    //    this.areaCode = in.readString();
    //    this.remark = in.readString();
    //    this.childList = new ArrayList<ChildInfo>();
    //    in.readList(this.childList, ChildInfo.class.getClassLoader());
    //}
    //
    //public static final Creator<StockInfo> CREATOR = new Creator<StockInfo>() {
    //    @Override public StockInfo createFromParcel(Parcel source) {
    //        return new StockInfo(source);
    //    }
    //
    //    @Override public StockInfo[] newArray(int size) {
    //        return new StockInfo[size];
    //    }
    //};
  }

  /**
   * 子单信息集合
   */
  public static class ChildInfo implements Serializable {
    private static final long serialVersionUID = 102L;
    //子单号或者包号
    private String childWaybillNo;
    //0是未扫描，1是已扫描
    private Integer flag;

    public String getChildWaybillNo() {
      return childWaybillNo;
    }

    public void setChildWaybillNo(String childWaybillNo) {
      this.childWaybillNo = childWaybillNo;
    }

    public Integer getFlag() {
      if (flag == null) {
        flag = 0;
      }
      return flag;
    }

    public void setFlag(Integer flag) {
      this.flag = flag;
    }

    //@Override public int describeContents() {
    //    return 0;
    //}
    //
    //@Override public void writeToParcel(Parcel dest, int flags) {
    //    dest.writeString(this.childWaybillNo);
    //    dest.writeValue(this.flag);
    //}
    //
    //public ChildInfo() {
    //}
    //
    //protected ChildInfo(Parcel in) {
    //    this.childWaybillNo = in.readString();
    //    this.flag = (Integer) in.readValue(Integer.class.getClassLoader());
    //}
    //
    //public static final Creator<ChildInfo> CREATOR = new Creator<ChildInfo>() {
    //    @Override public ChildInfo createFromParcel(Parcel source) {
    //        return new ChildInfo(source);
    //    }
    //
    //    @Override public ChildInfo[] newArray(int size) {
    //        return new ChildInfo[size];
    //    }
    //};
  }

  /**
   * 总件数
   */
  public static int getTotaljian(List<StockInfo> list) {
    int count = 0;
    for (int i = 0; i < list.size(); i++) {
      StockInfo itemInfo = list.get(i);
      count += itemInfo.getChildList().size();
    }
    return count;
  }

  /**
   * 实操票
   */
  public static int getHoldpiao(List<StockInfo> list) {
    int count = 0;
    for (int i = 0; i < list.size(); i++) {
      StockInfo itemInfo = list.get(i);
      List<ChildInfo> childList = itemInfo.getChildList();
      if (childList.size() > 0) {
        for (ChildInfo item : childList) {
          if (item.getFlag() == 1) {
            count++;
            break;
          }
        }
      }
    }
    return count;
  }

  /**
   * 实操件
   */
  public static int getHoldjian(List<StockInfo> list) {
    int count = 0;
    for (int i = 0; i < list.size(); i++) {
      StockInfo itemInfo = list.get(i);
      List<ChildInfo> childList = itemInfo.getChildList();
      if (childList.size() > 0) {
        for (ChildInfo item : childList) {
          if (item.getFlag() == 1) {
            count++;
          }
        }
      }
    }
    return count;
  }

  /**
   * 总的实际重量
   */
  public static double getTotalWeight(List<StockInfo> list) {
    double totalWeight = 0.0;
    for (StockInfo stockInfo : list) {
      totalWeight += stockInfo.getWeight().doubleValue();
    }
    return totalWeight;
  }

  /**
   * 总的计费重量
   */
  public static double getTotalChargedWeight(List<StockInfo> list) {
    double totalWeight = 0.0;
    for (StockInfo stockInfo : list) {
      totalWeight += stockInfo.getChargedWeight().doubleValue();
    }
    return totalWeight;
  }

  /**
   * 总的体积
   */
  public static double getTotalVolume(List<StockInfo> list) {
    double totalVolume = 0.0;
    for (StockInfo stockInfo : list) {
      totalVolume += stockInfo.getVolume().doubleValue();
    }
    return totalVolume;
  }
}
